package com.tansuo365.test1.service.otherservice.impl;

import com.tansuo365.test1.bean.otherbean.Role;
import com.tansuo365.test1.bean.otherbean.User;
import com.tansuo365.test1.mapper.othermapper.RoleMapper;
import com.tansuo365.test1.mapper.othermapper.UserRoleMapper;
import com.tansuo365.test1.service.otherservice.RoleService;
import com.tansuo365.test1.service.otherservice.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*角色服务实现层*/
@Service
public class RoleServiceImpl implements RoleService {

	@Resource
	private RoleMapper roleMapper;
	@Resource
	private UserRoleMapper userRoleMapper;
	@Resource
	private UserService userService;
//	@Override
//	public Set<String> listRoleNames(String userName) {
//		Set<String> result = new HashSet<>();
//		List<Role> roles = listRoles(userName);
//		for (Role role : roles) {
//			result.add(role.getName());
//		}
//		return result;
//	}
//	@Override
//	public List<Role> listRoles(String userName) {
//		List<Role> roles = new ArrayList<>();
//		User user = userService.getByName(userName);
//		if (null == user)
//			return roles;
//
//		roles = listRoles(user);
//		return roles;
//	}
	@Override
	public void add(Role role) {
		roleMapper.insertSelective(role);
	}

	@Override
	public int addSelective(Role role) {
		return roleMapper.insertSelective(role);
	}

	@Override
	public int delete(int id) {
		return roleMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int deleteByUserId(int id) {
		return roleMapper.deleteByUserId(id);
	}

	@Override
	public int update(Role role) {
		return roleMapper.updateByPrimaryKeySelective(role);
	}

	@Override
	public Role getByName(String name) {
		return roleMapper.selectByName(name);
	}

	@Override
	public Role get(int id) {
		return roleMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Role> listSelective(Role role) {
		return roleMapper.selectRoleSelective(role);
	}

	@Override
	public List<Role> listRolesByUserId(int id) {
		return roleMapper.selectByUserId3Table(id);
	}

	@Override
	public List<Role> listRoles(User user) {
		return roleMapper.selectByUserId3Table(user.getId());
	}

	@Override
	public List<Role> list() {
		return roleMapper.selectRoleList();
	}

}